package com.example.gateway.config;

import com.example.gateway.filter.LoggingFilter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;

@Configuration
public class WebConfiguration {

    /**
     * 注册日志过滤器（默认）
     * <p>
     * 不用@Component直接注入，以确保只有在应用中没有定义该类型的bean时才会使用默认实现
     *
     * @return 注册日志过滤器
     */
    @Order(Ordered.HIGHEST_PRECEDENCE)
    @Bean
    @ConditionalOnMissingBean
    public GlobalFilter loggingFilter() {
        return new LoggingFilter();
    }
}
